//
//  HomeCell.m
//  Custom_Weibo
//
//  Created by LEO on 12/11/15.
//  Copyright © 2015 Leo_Lei. All rights reserved.
//

#import "HomeCell.h"

@implementation HomeCell

#pragma mark - INITIALIZATION_METHODS
/*  If you create cell only in code, you should override 'init with Frame' 
 and 'init with aCoder' method.
 */
- (void)awakeFromNib {
    // Initialization code
    _weiboView = [[HomeView alloc] initWithFrame:CGRectZero];
    [self addSubview:_weiboView];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

#pragma mark - SET_NEW_FRAME
- (void)setLayoutFrame:(WeiboViewLayoutFrame *)layoutFrame {
    if (_layoutFrame != layoutFrame) {
        _layoutFrame = layoutFrame;
        self.weiboView.layoutFrame = _layoutFrame;
        [self setNeedsLayout];
    }
}

#pragma mark - LOAD_VIEW
- (void)layoutSubviews {
    [super layoutSubviews];
    
    /*  Set data for each componets through weibo model.
     */
    WeiboModel *_model = _layoutFrame.weiboModel;
    _weiboView.frame = _layoutFrame.mainFrame;
    _userName.text = _model.userModel.screen_name;
    
    NSString *userImage = _model.userModel.profile_image_url;
    NSURL *url = [NSURL URLWithString:userImage];
    [_userImage sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"Icon"]];

    _comment.text = [NSString stringWithFormat:@"评论:%@", _model.commentsCount];
    _repost.text = [NSString stringWithFormat:@"转发:%@", _model.repostsCount];
    _source.text = [NSString stringWithFormat:@"来源:%@", _model.source];
}

@end
